<template>
  <div class="tqyb-content">
    <div class="left">
      <p class="wd">{{ weatherData.temperature }}°C</p>
      <p class="text">当前温度</p>
    </div>
    <div class="right">
      <p class="textr">风速：{{ weatherData.speed }}m/s</p>
      <p class="textr">风力：{{ weatherData.force }}级</p>
      <p class="textr">风向：{{ weatherData.direction }}</p>
    </div>
    <div class="right">
      <p class="textr">相对湿度：{{ weatherData.humidity }}m/s</p>
      <p class="textr">PM2.5：{{ weatherData.pm25 }}级</p>
      <p class="textr">PM10：{{ weatherData.pm100 }}</p>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { getWeatherdata } from '@/api/zlcj.js';

// 假设的API密钥和城市ID
const apiKey = 'YOUR_API_KEY'; // 替换为你的API密钥
const cityId = '101010100'; // 替换为你的城市ID

// 定义响应式数据
const weatherData = ref({
  humidity: '--',
  speed: '--',
  direction: '--',
  wind_direction: '--',
  force: '--',
  pm25: '--',
  pm100: '--',
});

// 获取天气数据的函数
const fetchWeatherData = async () => {
  try {
    let { data } = await getWeatherdata();
    weatherData.value = data;
  } catch (error) {
    console.error('获取天气数据失败', error);
  }
};

// 页面挂载时获取天气数据
onMounted(() => {
  fetchWeatherData();
});
</script>

<style lang="scss">
.tqyb-content {
  width: 450px;
  // height: 155px;
  height: 12%;
  background: url('@/assets/images/tqbg.png') no-repeat;
  background-size: 100% 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 20px;
  .left {
    width: 30%;
    border-right: 1px solid rgba(255, 255, 255, 0.3);
    text-align: center;
    padding-right: 30px;
    .wd {
      font-family: PingFangSC, PingFang SC;
      font-weight: 600;
      font-size: 28px;
      color: #ffffff;
      line-height: 40px;
      margin-bottom: 14px;
    }
    .text {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #ffffff;
      line-height: 17px;
    }
  }
  .right {
    .textr {
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 12px;
      color: #ffffff;
      line-height: 17px;
      margin-bottom: 8px;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}
</style>
